// let cpus=(a,b)=>{
//     return a
// }
// module.exports=cpus

let Commander=require("commander")//引入commander
let Inquirer=require("inquirer")//引入inquirer
// let Blessed=require("blessed")
let Blessed_contrib=require("blessed-contrib")
let p=require("lodash")
let ps=require("current-processes")
console.log(55)
function rend(){

    ps.get(function(err,processes){
        var sorted=p.sortBy(processes,'cpu')
        var top5=sorted.reverse().splice(0,5)
        // console.log(top5)//打印cpu
        let x=top5.map(item=>item.cpu)
        let y=top5.map(item=>item.name)
        // console.log(x)
        var blessed = require('blessed')
        , contrib = require('blessed-contrib')
        , screen = blessed.screen()
        , line = contrib.line(
            { style:
              { line: "yellow"
              , text: "green"
              , baseline: "black"}
            , xLabelPadding: 3
            , xPadding: 5
            , label: 'cpu'})
        , data = {
            x: y,
            y: x
         }
      screen.append(line) //must append before setting data
      line.setData([data])
    
      screen.key(['escape', 'q', 'C-c'], function(ch, key) {
        return process.exit(0);
      });
    
      screen.render()
    
    })
}
setInterval(rend,500)
rend()

module.exports=rend